package test;

public class pd2 {
    public static void main(String[] args) {
        char s1,s2,s3,s4;
        for(s1='A'; s1<='E'; s1++){
            for(s2='A'; s2<='E'; s2++){
                for(s3='A'; s3<='E'; s3++){
                    for(s4='A'; s4<='E'; s4++){
                        if((s1=='B'||s4=='C')&&(s2=='B'||s4=='A')&&(s1=='A'||s3=='A')&&(s2=='D'||s3=='C') && !((s1=='B'&&s4=='C')||(s2=='B'&&s4=='A')||(s1=='A'&&s3=='A')||(s2=='D'&&s3=='C'))){
                            System.out.println(s1+" "+s2+" "+s3+" "+s4);
                        }
                    }
                }
            }
        }
    }
}
